﻿using EMS.system.EntityAppService.MasterData.SupplierManagementService;
using EMS.system.IEntityAppService.MasterData.ProcurementWarehousingServices;
using EMS.system.IEntityAppService.MasterData.ProcurementWarehousingServices.ProcurementWarehousingServicesDto;
using EMS.system.IEntityAppService.MasterData.SupplierManagementIService;
using EMS.system.IEntityAppService.MasterData.SupplierManagementIService.SupplierManagementDto;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace EMS.system.Web.Controllers.MasterData.ProcurementWarehousing
{
    public class ProcurementWarehousingHomeController : Controller
    {
        private readonly IProcurementWarehousAppService _procurementWarehousingService;

        public ProcurementWarehousingHomeController(IProcurementWarehousAppService procurementWarehousingService)
        {
            _procurementWarehousingService = procurementWarehousingService;
        }
        /// <summary>
        /// 采购入库
        /// </summary>
        /// <returns></returns>
        public IActionResult ProcurementWarehousing()
        {
            return View();
        }

        /// <summary>
        /// 采购入库显示
        /// </summary>
        /// <param name="LbounListCode"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetProcurementWarehousing(string? LbounListCode, int page, int limit)
        {
            var (units, total) = _procurementWarehousingService.GetProcurementWarehousing(LbounListCode, page, limit);
            return Json(new { code = 0, data = units, total = total });
        }
        /// <summary>
        /// 采购入库新增
        /// </summary>
        /// <returns></returns>
        public IActionResult AddProcurementWarehousing()
        {
            return View();
        }
        /// <summary>
        /// 采购入库新增
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public JsonResult Add(ProcurementWarehousServicesDto dto)
        {
            var list = _procurementWarehousingService.InsertProcurementWarehousingServicesDto(dto);
            return Json(new { code = 1, msg = "新增成功" });
        }
        /// <summary>
        /// 采购入库修改
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdateProcurementWarehousing(int id)
        {
            ViewBag.id = id;
            return View();
        }
        /// <summary>
        /// 采购入库反填
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> SelectUpdate(int id)
        {
            var list = await _procurementWarehousingService.GetUpdate(id);
            return Json(new { data = list, msg = "反填成功" });
        }
        /// <summary>
        /// 采购入库修改
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public Task<int> Update(ProcurementWarehousServicesDto dto)
        {
            var list = _procurementWarehousingService.UpdateProcurementWarehousing(dto);
            return Task.FromResult(1);
        }
        /// <summary>
        /// 采购入库删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<int> Delete(int id)
        {
            var list = _procurementWarehousingService.DeleteProcurementWarehousing(id);
            return Task.FromResult(1);
        }

    }
}
